// 混淆 https://www.jianshu.com/p/882f3585446f

const mixin = {
	data() {
		return {
			dataList: {
				data: [], //接口数据
				isLoading: false, //是否加载下一页
				num: 1 //当前页数
			},
			pageApi: '', //请求接口
			pageData: {} //请求数据
		}
	},
	methods: {
		//刷新列表
		getLists(type) {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 300
			});
			this.dataList = {
				data: [], //列表数据
				isLoading: false, //是否加载下一页
				num: 1 //当前页数
			}
			this.getList(type)
		},
		getList(type) {
			var that = this
			if (!this.dataList.isLoading) {
				this.$store.dispatch(this.pageApi, {
					pageNo: this.dataList.num,
					pageSize: 10,
					...this.pageData
				}).then(res => {
					if (type) { //调用传来的函数名，将数据抛出去
						that[type](res)
					} else {
					    this.dataList.data = this.dataList.data.concat(res.dataList)
                    }
					this.dataList.num++
					if (this.dataList.num > res.totalPage) {
						this.dataList.isLoading = true
					}
				}).catch(err => {
					console.log(err)
				})

			}
		}
	},
	onReachBottom() {
		this.getList()
	}
}
export default mixin;